'use static';
zmvp
.run(
    function($rootScope, $location, $window, $http, $state,$timeout){
        $rootScope.$on('$stateChangeStart', function (event, toState, toStateParams) {
            $rootScope.toState = toState;
            $rootScope.toStateParams = toStateParams;
            if($rootScope.toState.name ==undefined){
                $state.go("mainPage");
            }
        });
        $rootScope.$on('$stateChangeSuccess', function (event, toState, toParams, fromState, fromParams) {
        });

        $rootScope.initDirtyCheck=function(){
        };
        $rootScope.initDirtyCheck();
        $rootScope.checkDirty=function(){
            if($rootScope.orgContactDirty) {
                if(!confirm("有数据未提交，确定要放弃修改人员信息么?")) return false;
                $rootScope.orgContactDirty=false;
            }
            return true;
        };
        $rootScope.stateStack=[];
        $rootScope.goSref=function(state){
            if ($rootScope.toState.name==state||$rootScope.checkDirty()==false) return false;
            else{
                $rootScope.stateStack.push($rootScope.toState.name);
                $state.go(state);
            }
            return true;
        };
        $rootScope.back=function(){
            if ($rootScope.checkDirty()==false) return false;
            $state.go($rootScope.stateStack.pop());
        }
    }
);
